package com.huang.app.antstore.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.huang.app.antstore.R;
import com.huang.app.antstore.databinding.ActivityAntStoreBinding;
import com.huang.app.antstore.fragment.FragmentTabLabor;
import com.huang.app.antstore.fragment.FragmentTabMine;
import com.huang.app.antstore.fragment.FragmentTabShop;
import com.huang.app.antstore.fragment.FragmentTabTrain;

public class AntStoreActivity extends AppCompatActivity {
    ActivityAntStoreBinding mAntStoreBinding;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    ft.replace(R.id.fl_content, FragmentTabShop.newInstance());
                    ft.commit();
                    return true;
                case R.id.navigation_dashboard:
                    ft.replace(R.id.fl_content, FragmentTabLabor.newInstance());
                    ft.commit();
                    return true;
                case R.id.navigation_notifications:
                    ft.replace(R.id.fl_content, FragmentTabTrain.newInstance());
                    ft.commit();
                    return true;
                case R.id.navigation_tab4:
                    ft.replace(R.id.fl_content, FragmentTabShop.newInstance());
                    ft.commit();
                    return true;
                case R.id.navigation_mine:
                    ft.replace(R.id.fl_content, FragmentTabMine.newInstance());
                    ft.commit();
                    return true;
            }

            return false;
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAntStoreBinding = DataBindingUtil.setContentView(this, R.layout.activity_ant_store);
        BottomNavigationView navigation = mAntStoreBinding.navigation;
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }

}
